package model

import (
	"car-rental-08-14/global"
	"gorm.io/gorm"
	"time"
)

type Car struct {
	Id           uint32         `gorm:"column:id;type:int UNSIGNED;comment:租车ID;primaryKey;not null;" form:"id" json:"id"`                               // 租车ID
	Title        string         `gorm:"column:title;type:varchar(60);comment:标题;not null;" form:"title" json:"title"`                                    // 标题
	Image        string         `gorm:"column:image;type:varchar(500);comment:图片;not null;" form:"image" json:"image"`                                   // 图片
	Price        float64        `gorm:"column:price;type:decimal(10, 2);comment:价格;not null;" form:"price" json:"price"`                                 // 价格
	PriceComment []byte         `gorm:"column:price_comment;type:tinyblob;comment:价格备注 1:天 2:月 3:年;not null;" form:"price_comment" json:"price_comment"` // 价格备注 1:天 2:月 3:年
	Status       []byte         `gorm:"column:status;type:tinyblob;comment:状态 1:待租 2:已租出;not null;" form:"status" json:"status"`                         // 状态 1:待租 2:已租出
	CreatedAt    time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" form:"created_at" json:"created_at"`
	UpdatedAt    time.Time      `gorm:"column:updated_at;type:datetime(3);not null;" form:"updated_at" json:"updated_at"`
	DeletedAt    gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" form:"deleted_at" json:"deleted_at"`
}

func (c *Car) Table() string {
	return "car"
}

func (c *Car) AddCar() error {
	return global.DB.Create(&c).Error
}

func (c *Car) UpdatedCar() error {
	return global.DB.Updates(&c).Error
}
